package com.xilihui.xlh.business.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.xilihui.xlh.R;
import com.xilihui.xlh.business.entities.WithdrawEntity;
import com.xilihui.xlh.business.requests.MineRequest;
import com.xilihui.xlh.core.app.BaseCompatActivity;
import com.xilihui.xlh.core.app.ToolBaseCompatActivity;
import com.xilihui.xlh.core.http.DoTransform;
import com.xilihui.xlh.core.http.HttpSubscriber;
import com.xilihui.xlh.core.util.LogUtil;
import com.xilihui.xlh.core.util.ToastUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/4.
 */

public class CommissionActivity extends ToolBaseCompatActivity{
    
    @BindView(R.id.tv_jiner)
    TextView tv_jiner;
    
    WithdrawEntity withdrawEntity = null;
    
    @Override
    public int getLayout() {
        return R.layout.activity_commission;
    }

    @Override
    public String initTitle() {
        return null;
    }
    
    @OnClick(R.id.iv_toolbar_left)
    public void back(){
        finish();
    }
    
    @OnClick(R.id.tv_toolbar_right)
    public void bill(){
        startActivity(new Intent(this,BillActivity.class));
    }

    @Override
    public void initUI(@Nullable Bundle savedInstanceState) {
        setToolTitle("我的佣金");
        setToolRightText("账单");
    }

    @Override
    public void initData() {
        getInfo();
    }

    public void getInfo(){

        MineRequest.withdrawInfo(CommissionActivity.this)
                .compose(DoTransform.<WithdrawEntity>applyScheduler(this,true))
                .compose(CommissionActivity.this.<WithdrawEntity>bindToLifecycle())
                .subscribe(new HttpSubscriber<WithdrawEntity>(this) {
                    @Override
                    protected void onSuccess(WithdrawEntity entity) {
                        tv_jiner.setText("￥"+entity.getUser_info().getMoney());
                        withdrawEntity = entity;
                    }

                    @Override
                    protected void onFail(String msg) {
                        ToastUtil.toastShortNegative(msg);
                    }
                });

    }
    
    @OnClick(R.id.tv_withdraw)
    public void withdraw(){
        if(withdrawEntity!=null){
            Intent intent = new Intent(CommissionActivity.this,WithdrawActivity.class);
            intent.putExtra("data",withdrawEntity);
            startActivity(intent);
        }else {
            ToastUtil.toastShortNegative("请重新打开该页面");
        }
        
    }
    
}
